﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Expo.Training.DataAccess.Activity;
using Expo.Training.BRule;
using System.IO;

public partial class Activity_EditActivity : PageBase
{
    private Guid _id;

    private ActivityEntity _model;

    protected void Page_Load(object sender, EventArgs e)
    {
        _id = new Guid(Request.QueryString["id"].ToString().Trim());

        _model = ActivityModule.GetActivity(_id);

        InitCecEditor();

        if (!IsPostBack)
        {
            Bind();
        }
    }

    private void Bind()
    {
        this.txtTitle.Text = _model.ActivityTitle;
        this.txtIntro.Content = _model.ActivityIntro;
        this.txtDestination.Text = _model.Destination;
        this.txtCount.Text = _model.Count.ToString();
    }

    private void InitCecEditor()
    {
        this.txtIntro.Show();
    }

    protected void btn_Edit_Click(object sender, EventArgs e)
    {
        string _title;
        string _intro;
        string _destination;
        int _count;

        _title = this.txtTitle.Text.Trim();
        _intro = this.txtIntro.Content.Trim();
        _destination = this.txtDestination.Text.Trim();
        _count = int.Parse(this.txtCount.Text.Trim());

        if (string.IsNullOrEmpty(_intro))
        {
            this.AddEndScript("input error", "$(\"valIntro\").show();$(\"introError\").innerText = \"必须填写活动简介\";");
            return;
        }

        _model.ActivityTitle = _title;
        _model.ActivityIntro = _intro;
        _model.Destination = _destination;
        _model.Count = _count;

        try
        {
            if (ActivityModule.Update(_model))
            {
                this.AddEndScript("update succes", "alert('修改活动成功！');location.href='ActivityManagement.aspx'");
            }
            else
            {
                this.AddEndScript("error", "alert('修改操作出错，请重试！');");
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}
